package com.yztc.utils;

import android.content.Context;
import android.widget.Toast;

import java.util.HashMap;

import cn.sharesdk.framework.Platform;
import cn.sharesdk.framework.PlatformActionListener;
import cn.sharesdk.framework.PlatformDb;
import cn.sharesdk.framework.ShareSDK;
import cn.sharesdk.sina.weibo.SinaWeibo;
import cn.sharesdk.tencent.qq.QQ;
import cn.sharesdk.wechat.friends.Wechat;

import static android.R.attr.action;

/**
 * Created by Administrator on 2016/10/24.
 */

public class OtherLogin {
    private static Context mContext;

        /**

         *新浪第三方登录

         */

        public void sinaLogoin(){

            ShareSDK.initSDK(mContext);

            Platform sina = ShareSDK.getPlatform(SinaWeibo.NAME);

            sina.SSOSetting(true);

            authorize(sina);

        }

        /**

         *微信第三方登录

         */

        public void weixinLogoin() {

            ShareSDK.initSDK(mContext);

            Platform wechat = ShareSDK.getPlatform(mContext, Wechat.NAME);

            wechat.SSOSetting(true);

            if (!wechat.isClientValid()) {

                Toast.makeText(mContext,

                        "微信未安装,请先安装微信",

                        Toast.LENGTH_LONG).show();

            }

            authorize(wechat);

        }

        /**

         * QQ第三方登录

         */

        public  void qqLogin() {

            ShareSDK.initSDK(mContext);

            Platform qq = ShareSDK.getPlatform(QQ.NAME);

            qq.SSOSetting(true);

            authorize(qq);

        }


        /**

         *第三方登录选择 要数据不要功能

         *

         *@paramplat

         */

        public static void authorize(Platform plat) {

            if (plat == null) {

                return;

            }

            plat.setPlatformActionListener((PlatformActionListener) mContext);

//关闭SSO授权

            plat.SSOSetting(false);

            plat.showUser(null);

        }



}
